<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: 'ID' })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table />

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { provide, ref } from 'vue'
import baTableClass from '/@/utils/baTable'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'

defineOptions({
    name: 'routine/staff',
})

const statusList = ref({})
const { t } = useI18n()
const baTable = new baTableClass(
    new baTableApi('staff/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
            { label: '用户ID', prop: 'user_id', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: '用户昵称', prop: 'user.nickname', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            {
                label: '姓名',
                prop: 'name',
                align: 'center',
                operator: 'LIKE',
            },
			{ label: '职位', prop: 'position', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: '手机号', prop: 'mobile', align: 'center', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
			{
			    label: t('State'),
			    prop: 'status',
			    align: 'center',
				operator: 'IN',
			    render: 'tag',
				custom: {0: 'danger', 1: 'success'},
				replaceValue: {0: '禁用', 1:'正常'},
			},
            { label: t('Create time'), prop: 'createtime', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
           
            {
                label: t('Operate'),
                align: 'center',
                width: '100',
                render: 'buttons',
                buttons: defaultOptButtons(['edit', 'delete']),
                operator: false,
            },
        ],
        dblClickNotEditColumn: [undefined],
    },
    {
        defaultItems: {
            status: 1,
        },
    },{},{
		getData({ res }) {
		    if (res && res.data) {
			   statusList.value = res.data.statusList
		    }
		},
		getEditData({ res }) {
		    if (res && res.data) {
				console.log(res)
		        baTable.form.items = res.data
		    }
		},
	}
)
// 重写auth方法，绕过权限控制，始终返回true
baTable.auth = function () {
    return true
}
baTable.mount()
baTable.getData()

provide('baTable', baTable)
</script>

<style scoped lang="scss"></style>
